#include <stdio.h>
int main()
{
	int arr[] = { 0,31,28,31,30,31,30,31,31,30,31,30,31 };
	int x = 0;
	int y = 0;
	while (scanf_s("%d %d", &x, &y) != EOF)
	{
		if ((x % 100 != 0 && x % 4 == 0) || x % 400 == 0)
			arr[2]++;
		printf("%d \n", arr[y]);
	}
	
	return 0;
}